package com.ruoyi.jl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.jl.domain.GameLog;
import com.ruoyi.jl.mapper.GameLogMapper;
import com.ruoyi.jl.service.IGameLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 玩家游玩日志 服务层实现
 *
 * @author wh
 * @date 2019-04-29
 */
@Slf4j
@Service
public class GameLogServiceImpl extends ServiceImpl<GameLogMapper, GameLog> implements IGameLogService {

    @Autowired
    GameLogMapper gameLogMapper;

    @Override
    public List<GameLog> list(GameLog gameLog) {
        // LambdaQueryWrapper<GameLog> wrapper = new LambdaQueryWrapper<>();
        QueryWrapper<GameLog> wrapper = new QueryWrapper<>();
        if (gameLog != null) {
            if (StringUtils.isNotEmpty(gameLog.getId())) {
                wrapper.eq("id", gameLog.getId());
            }
            if (StringUtils.isNotEmpty(gameLog.getGameId())) {
                wrapper.eq("game_id", gameLog.getGameId());
            }
            if (StringUtils.isNotEmpty(gameLog.getPlayerId())) {
                wrapper.eq("player_id", gameLog.getPlayerId());
            }
            if (StringUtils.isNotEmpty(gameLog.getProfitGold())) {
                wrapper.eq("profit_gold", gameLog.getProfitGold());
            }
            if (StringUtils.isNotEmpty(gameLog.getUseChannel())) {
                wrapper.eq("use_channel", gameLog.getUseChannel());
            }

            if (StringUtils.isNotEmpty(gameLog.getParams().get("beginTime"))) {
                wrapper.ge("create_time", gameLog.getParams().get("beginTime"));
            }
            if (StringUtils.isNotEmpty(gameLog.getParams().get("endTime"))) {
                wrapper.le("create_time", gameLog.getParams().get("endTime"));
            }
        }
        return baseMapper.selectList(wrapper);
    }

    @Override
    public Integer countGold(String playerId) {
        return gameLogMapper.countGold(playerId);
    }
}
